<template>
  <Layout desc="使用 animation steps 实现打字机动效">
    <div class="mt-60">
      <div class="typewriter-effect">
        <div class="text" :style="{ '--characters': text.length }">
          {{ text }}
        </div>
      </div>
    </div>
  </Layout>
</template>

<script setup lang="ts">
const text = '锦瑟无端五十弦，一弦一柱思华年。'
</script>

<style scoped lang="scss">
.typewriter-effect {
  display: flex;
  font-size: 32px;
}

.typewriter-effect > .text {
  max-width: 0;
  animation: typing 4s steps(var(--characters)) infinite;
  white-space: nowrap;
  overflow: hidden;
}

.typewriter-effect::after {
  content: ' |';
  animation: blink 1s infinite;
  animation-timing-function: step-end;
}

@keyframes typing {
  75%,
  100% {
    max-width: calc(var(--characters) * 2.5ch);
  }
}

@keyframes blink {
  0%,
  75%,
  100% {
    opacity: 1;
  }
  25% {
    opacity: 0;
  }
}
</style>
